import {Describer} from "./base";


const map = '日一二三四五六日'.split('')


const numberToHans = (number) => map[number]

export const numberToWeekHans = number => `周${numberToHans(number)}`


export class WeekPartDescriber extends Describer {
  singleNumberSegment(exp: string): string {
    return `周${numberToHans(exp)}`
  }

  spanSegment(exp: string): string {
    const {start, end} = super.parseSpan(exp)
    return `周${numberToHans(start)}到周${numberToHans(end)}`;
  }

  spanSlashNumberSegment(exp: string): string {
    const {start, end, interval} = super.parseSpanSlashNumber(exp)
    return `周${numberToHans(start)}到周${numberToHans(end)}每隔${interval}天`;
  }

  starSegment(exp: string): string {
    return "";
  }

  starSlashNumberSegment(exp: string): string {
    const interval = Number(exp.replace('*/', ''))
    if (interval === 1) {
      return ''
    }

    const days = []
    for (let wd = 0; wd <= 6; wd += interval) {
      days.push(wd)
    }

    return days.map((d) => `周${numberToHans(d)}`).join(',')
  }
}
